﻿using System;
namespace ShapesConsole
{
    //形状的接口定义
    public interface Shapes
    {
        public abstract double getArea();
        public abstract bool isLegal();

    }

    //矩形类
    public class Rectangle : Shapes
    {
        private double weight, height;
        public Rectangle(double weight, double height)
        {
            this.weight = weight;
            this.height = height;
        }
        public double Weight
        {
            get { return weight; }
            set { weight = value; }
        }

        public double Height
        {
            get { return height; }
            set { height = value; }

        }
        public double getArea()
        {
            return weight * height;
        }

        public bool isLegal()
        {
            return (weight == 0 && height == 0);
        }
    }

    //正方形类
    public class Square : Shapes
    {
        private double side;
        public double Side
        {
            get { return side; }
            set { side = value; }
        }
        public double getArea()
        {
            return side * side;
        }

        public bool isLegal()
        {
            return side > 0;
        }
    }

    //三角形类
    public class Triangle : Shapes
    {
        double side1, side2, side3;
        public double getArea()
        {
            double p = side1 + side2 + side3;
            return Math.Sqrt(p * (p-side1)*(p-side2)*(p-side3));
        }

        public bool isLegal()
        {
            return (side1 > 0 && side2 > 0 && side3 > 0);
        }
    }


}
